package com.hd.tiyu.yuejian.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.hd.tiyu.yuejian.JavaBean.Train;
import com.hd.tiyu.yuejian.Model.ItemposModel;
import com.hd.tiyu.yuejian.Model.ListsModel;
import com.hd.tiyu.yuejian.R;
import com.squareup.picasso.Picasso;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Administrator on 2017/10/10.
 */

public class TrainActivity extends AppCompatActivity {
    private TextView name,introduction,update_time,Place,bmnotice,price;
    private ImageView img;
    private Button baoming;
    private Train data;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_train);
        initViews();
        initEvents();
        initData();
    }
    private void initViews() {
        baoming=(Button)findViewById(R.id.train_baoming);
        img=(ImageView)findViewById(R.id.train_imageView);
        name= (TextView) findViewById(R.id.top_name);
        introduction=(TextView)findViewById(R.id.train_introduction);
        update_time=(TextView)findViewById(R.id.train_update_time);
        Place=(TextView)findViewById(R.id.train_scene_name);
        bmnotice=(TextView)findViewById(R.id.train_bmnotice);
        price=(TextView)findViewById(R.id.train_price);
    }

    private void initData() {
        Intent intent=getIntent();
        String id=intent.getStringExtra("id");
        ListsModel model=new ListsModel();
        Call<Train>call=model.getTrain(id);
        call.enqueue(new Callback<Train>() {
            @Override
            public void onResponse(Call<Train> call, Response<Train> response) {
                data=response.body();
                name.setText(data.getName());
                introduction.setText(data.getIntro());
                update_time.setText(data.getUpdate_time());
                bmnotice.setText(data.getBmnotice());
                Place.setText(data.getPlace());
                price.setText(data.getPrice());
                Picasso.with(TrainActivity.this).load("http://172.24.10.175/workout/Uploads/"+data.getThumb()).resize(350,150).centerCrop().into(img);
            }
            @Override
            public void onFailure(Call<Train> call, Throwable t) {
            }
        });
    }

    private void initEvents() {
        baoming.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(TrainActivity.this,EnrolActivity.class);
                intent.putExtra("id",data.getId());
                startActivity(intent);
            }
        });
    }


}
